// pages/index/index.js
const ajax = require('../../../utils/quest.js');

Page({

  /**
   * 页面的初始数据
   */
  data: {
    storeAdvList: [{
        image: 'https://cdn.uviewui.com/uview/swiper/1.jpg',
        title: '昨夜星辰昨夜风，画楼西畔桂堂东'
      },
      {
        image: 'https://cdn.uviewui.com/uview/swiper/2.jpg',
        title: '身无彩凤双飞翼，心有灵犀一点通'
      },
      {
        image: 'https://cdn.uviewui.com/uview/swiper/3.jpg',
        title: '谁念西风独自凉，萧萧黄叶闭疏窗，沉思往事立残阳'
      }
    ],
    limit: 4,
    page: 1,
    limitAdvisory: 2,
    pageAdvisory: 1,
    advisoryList: [],
    limitPerson: 10,
    pagePerson: 1,
    personList: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getList()
    this.getAdvisory()
    this.getPerson()
  },
  bandAdvisory: function () {
    wx.navigateTo({
      url: '/pages/index/advisory/index'
    })
  },
  bandMore: function () {
    wx.navigateTo({
      url: '/pages/index/activity/index'
    })
  },
  bandApply: function (e) {
    const id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/pages/index/apply/index?id=' + id,
    })
  },
  bandIntelligent: function () {
    wx.navigateTo({
      url: '/pages/index/intelligent/index',
    })
  },

  bandJock: function (e) {
    const id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/pages/index/intelligentDetail/index?id=' + id,
    })
  },
  getList: function () {
    const {
      limit,
      page
    } = this.data
    let url = '/activity/list?limit=' + limit + '&page=' + page
    ajax.sendRequest(url, 'get', ).then(res => {
      const {
        code,
        page
      } = res.data
      if (code === 0) {
        this.setData({
          activity: page.list
        })
      }
    })
  },
  getAdvisory: function () {
    const {
      limitAdvisory,
      pageAdvisory
    } = this.data
    let url = '/information/list?limit=' + limitAdvisory + '&page=' + pageAdvisory
    ajax.sendRequest(url, 'get', ).then(res => {
      const {
        code,
        page
      } = res.data
      if (code === 0) {
        this.setData({
          advisoryList: page.list
        })
      }
    })
  },
  getPerson: function () {
    const {
      limitPerson,
      pagePerson
    } = this.data
    let url = '/richman/list?limit=' + limitPerson + '&page=' + pagePerson
    ajax.sendRequest(url, 'get', ).then(res => {
      const {
        code,
        page
      } = res.data
      if (code === 0) {
        this.setData({
          personList: page.list
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})